<?php
	class Fenxiao_setting_model extends CI_Model{

	 	function __construct(){
        	parent::__construct();
    	}

      /**
       * 获取分销设置
       * @param  [type] $school_id [description]
       * @return [type]            [description]
       */
      public function get_setting($school_id)
      {
        $sql = "select * from {$this->db->dbprefix}m_fenxiao_setting where school_id = $school_id";
        return $this->db->query($sql)->row_array();
      }

      /**
       * 设置
       * @param  [type] $school_id [description]
       * @param  [type] $data      [description]
       * @return [type]            [description]
       */
      public function setting($school_id,$data)
      {
        $setting = $this->get_setting($school_id);
        if(empty($setting))
        {
          //添加
          $data['school_id'] = $school_id;
          $data['add_time'] = time();
          return $this->db->insert('m_fenxiao_setting',$data);
        }else{
          return $this->db->update('m_fenxiao_setting',$data, array('school_id' => $school_id ));
        }
      }

  }
